﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using MediaAssistant.DAL;
using System.Linq;
namespace MediaAssistant.Controls.MusicList
{
    [Export(typeof(IMusicListView))]
    public partial class MusicListView:IMusicListView
    {
        public MusicListView()
        {
            InitializeComponent();
        }

        public IEnumerable<Music> GetSelectedMusics()
        {
            return Grid.SelectedItems.Cast<Music>();
        }

        public void ScrollIntoView(Music music)
        {
            if (music != null)
                Grid.ScrollIntoView(music);
        }

        private void HandleMouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            var element = e.OriginalSource as FrameworkElement;
            if(element.DataContext is Music)
            {
                var selectedItem = Grid.SelectedItem as Music;
                if (selectedItem != null)
                    ((MusicListPresenter) DataContext).OnItemDoubleClicked(selectedItem);
            }
        }
    }
}
